#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

int wordToNumber(const std::string& word) {
    if (word == "zero") return 0;
    if (word == "one") return 1;
    if (word == "two") return 2;
    if (word == "three") return 3;
    if (word == "four") return 4;
    if (word == "five") return 5;
    if (word == "six") return 6;
    if (word == "seven") return 7;
    if (word == "eight") return 8;
    if (word == "nine") return 9;
    return -1; // Неверный ввод
}

bool isPrime(int n) {
    if (n <= 1) return false;
    for (int i = 2; i <= sqrt(n); ++i) {
        if (n % i == 0) return false;
    }
    return true;
}

int findNearestPrime(int num) {
    int diff = 0;
    while (true) {
        if (isPrime(num - diff) && (num - diff) > 1) return num - diff;
        if (isPrime(num + diff)) return num + diff;
        ++diff;
    }
}

int main() {
    std::vector<std::string> words(3);
    std::cin >> words[0] >> words[1] >> words[2];

    int num = 0;
    for (const auto& word : words) {
        int digit = wordToNumber(word);
        if (digit == -1) {
            std::cout << "Wrong input" << std::endl;
            return 0;
        }
        num = num * 10 + digit;
    }

    std::cout << findNearestPrime(num) << std::endl;
    return 0;
}